package com.crm.system.service.impl.cluePoolManager;

import com.crm.common.model.DhPageInfo;
import com.crm.common.util.CommonUtils;
import com.crm.model.entity.cluePoolManager.ClueReceive;
import com.crm.model.vo.cluePoolManager.ClueReceiveVO;
import com.crm.service.cluePoolManager.ClueReceiveDbService;
import com.crm.system.service.cluePoolManager.ClueReceiveService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @ Author ：pym
 * @ Date   ：2021/1/8 13:05
 */
@Service
public class ClueReceiveServiceImpl implements ClueReceiveService {
    @Autowired
    ClueReceiveDbService clueReceiveDbService;

    /**
     * 线索池详情-线索清单-领取记录
     * @param pageIndex     ---页码
     * @param pageSize      ---分页大小
     * @param clueId        ---线索Id
     * @return
     */
    @Override
    public DhPageInfo<ClueReceiveVO> selectClueReceiveVOList(Integer pageIndex, Integer pageSize, String clueId) {
        if(pageIndex!=null&&pageSize!=null) {
            PageHelper.startPage(pageIndex, pageSize);
        }
        List<ClueReceiveVO> clueReceiveVOList = clueReceiveDbService.selectClueReceiveVOList(clueId);
        PageInfo<ClueReceiveVO> pageInfo = new PageInfo<>();
        return new DhPageInfo<ClueReceiveVO>(pageInfo, clueReceiveVOList);
    }

    /**
     *新增一条领取/分配记录
     * @param fromId       ---原线索池id
     * @param toId         ---新线索池id
     * @param clueId       ---线索ID
     * @param accountId    ---被分配人/领取人ID
     * @param receiveWay   ---领取方式：1-领取；2:分配
     * @return
     */
    @Override
    public Boolean insertClueReceive(String fromId,String toId,String clueId, String accountId, Integer receiveWay) {
        return clueReceiveDbService.insertClueReceive(fromId,toId,clueId,accountId,receiveWay);
    }

    @Override
    public long selectReceiveCountForCurrentMonthByPoolId(String cluePoolId, String yearMonth) {
        long result = clueReceiveDbService.selectReceiveCountForCurrentMonthByPoolId(cluePoolId,yearMonth);
        return result;
    }

    @Override
    public long selectClueReceiveByPoolId(String cluePoolId) {
        long result = clueReceiveDbService.selectClueReceiveByPoolId(cluePoolId);
        return result;
    }
}
